package com.yuanqiworld.vw.domain;

import org.apache.commons.io.IOUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.roo.addon.dod.RooDataOnDemand;

import java.io.IOException;
import java.util.Collection;

@RooDataOnDemand(entity = Metadata.class)
public class MetadataDataOnDemand {
    public static void main(String[] args) throws IOException {
        // 启动前请将<property name="hibernate.hbm2ddl.auto" value="create"/>.
        new ClassPathXmlApplicationContext("classpath:/META-INF/spring/applicationContext.xml");
        initDB();
    }

    public static void initDB() throws IOException {
        AuthorityInfoDataOnDemand.initDB();
        String json = IOUtils.toString(MetadataDataOnDemand.class.getClassLoader().getResource("Metadata.json"));
        Collection<Metadata> metadatas = Metadata.fromJsonArrayToMetadatas(json);
        for (Metadata metadata : metadatas) {
            metadata.merge();
        }
    }
}
